﻿' ******************************************************************************
' ** 
' **  Yahoo! Managed
' **  Written by Marius Häusler 2011
' **  It would be pleasant, if you contact me when you are using this code.
' **  Contact: YahooFinanceManaged@gmail.com
' **  Project Home: http://code.google.com/p/yahoo-finance-managed/
' **  
' ******************************************************************************
' **  
' **  Copyright 2011 Marius Häusler
' **  
' **  Licensed under the Apache License, Version 2.0 (the "License");
' **  you may not use this file except in compliance with the License.
' **  You may obtain a copy of the License at
' **  
' **    http://www.apache.org/licenses/LICENSE-2.0
' **  
' **  Unless required by applicable law or agreed to in writing, software
' **  distributed under the License is distributed on an "AS IS" BASIS,
' **  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' **  See the License for the specific language governing permissions and
' **  limitations under the License.
' ** 
' ******************************************************************************


Namespace YahooManaged.Weather

    Public Class Condition
        Public Property Description() As String
        Public Property Type() As ConditionType
        Public Property ForecastDate() As DateTime
        Public ReadOnly Property ImageNightUri As Uri
            Get
                Return Me.ConditionImageUri(True)
            End Get
        End Property
        Public ReadOnly Property ImageDayUri As Uri
            Get
                Return Me.ConditionImageUri(False)
            End Get
        End Property

        Public Function GetAutoImage(ByVal astro As AstronomyInfo) As Uri
            Dim fcTime As DateTime = #12:00:00 AM#.AddHours(Me.ForecastDate.Hour).AddMinutes(Me.ForecastDate.Minute)
            If DateTime.UtcNow.Hour = fcTime.Hour And Date.UtcNow.Minute = fcTime.Minute Then
                Return Me.ImageDayUri
            ElseIf fcTime > astro.Sunrise And fcTime < astro.Sunset Then
                Return Me.ImageDayUri
            Else
                Return Me.ImageNightUri
            End If
        End Function

        Private Function ConditionImageUri(ByVal isNight As Boolean) As Uri
            If Me.Type <> ConditionType.Not_Available Then
                Dim dayNightTag As String = "d"
                If isNight Then dayNightTag = "n"
                Return New Uri("http://l.yimg.com/a/i/us/nws/weather/gr/" & CInt(Me.Type).ToString & dayNightTag & ".png")
            Else
                Return Nothing
            End If
        End Function
    End Class

    Public Class ActualCondition
        Inherits Condition
        Public Property Temperature() As Integer
        Public Property TimeZoneId As String
    End Class

    Public Class Forecast
        Inherits Condition
        Public Property Day() As DayOfWeek
        Public Property HighTemperature() As Integer
        Public Property LowTemperature() As Integer
    End Class

End Namespace